// pages/wode/myInfo/myInfo.js
const app = getApp();
var njzxw = require('../../../utils/njzxw.js');
var url = require('../../../utils/url.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    /**
       * 到港时间
       */
    date: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    njzxw.initFun(this);
  },
  /**
     * 选择到港时间
     */
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var $this = this;
    this.loadData($this);
    njzxw.addSubmit({
      page: this,
      checkUser: true,
      url: url.saveInfo,
      verify: function (b) {
        console.log(b);
        if (b.name == '') {
          return "请输入您的姓名";
        }
        if ($this.data.date == '') {
          return "请选择生日";
        }
        if (b.height == '') {
          return "请输入正确的身高";
        }
        if (b.weight == '') {
          return "请输入正确的体重";
        }
        if (b.phone == '') {
          return "请输入您的联系电话";
        }
        // if (b.past_history == '') {
        //   return "在咨询内容里面填写点东西吧";
        // }
        b.past_history = njzxw.emoji(b.past_history);
        b['birth_time'] = $this.data.date;
        var n = {};
        njzxw.extend(n, b);
        b['data'] = n;
        b['wexi_id'] = $this.data.fromData.wexi_id;
        console.log(b);
        return b;
      }
    });
  },
  loadData: function ($this){
    njzxw.ajax({
      url: url.wxInfo,
      load:true,
      fun:function(a,b){
        wx.hideLoading();
        if(a){
          if(b.data.state == 1){
            $this.setData({
              fromData: b.data.data,
              date: b.data.data.birth_time,
            });
          }else{
            njzxw.alert({msg:b.data.msg});
          }
        }else{
          njzxw.alert({msg:'数据获取失败'});
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})